import {message} from 'antd';
import {formatMessage} from './intl';
import {paymentType, transportType} from '../Enum';

export const newOrUpdateValidator = data => {
    //增加判断必填字段
    const emptyErrors = [];
    if(!data || !data.expectDepartedDate)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.expectDepartedDate',
            defaultMessage: '预计离港日期'
        }));
    if(!data || !data.declarePlace)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.declarePlace',
            defaultMessage: '报关地点'
        }));
    if(!data || !data.declareType)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.declareType',
            defaultMessage: '报关类型'
        }));
    if(!data || (data.paymentType === paymentType['L/C'] && !data.lcCode))
        emptyErrors.push(formatMessage({
            id: 'validator.empty.lcCode',
            defaultMessage: '信用证编号'
        }));
    if(!data || data.shortContainerCount === null)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.shortContainerCount',
            defaultMessage: '20GP'
        }));
    if(!data || data.standardContainerCount === null)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.standardContainerCount',
            defaultMessage: '40HQ'
        }));
    if(!data || data.highContainerCount === null)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.highContainerCount',
            defaultMessage: '40GP'
        }));
    if(emptyErrors.length > 0) {
        message.warning(`${emptyErrors.join('，')}${formatMessage({
            id: 'validator.required',
            defaultMessage: '必填!'
        })}`);
        return false;
    }
    if(!data.isLcl && (data.shipmentType !== transportType.空运 && data.shipmentType !== transportType.快递) && data.highContainerCount === 0 &&
        data.standardContainerCount === 0 && data.shortContainerCount === 0) {
        message.warning(`${emptyErrors.join('，')}${formatMessage({
            id: 'validator.empty.containerCount',
            defaultMessage: '20GP,40HQ,40GP不能都为0'
        })}`);
        return false;
    }
    return true;
};
